<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript" src="../js/vue.js"></script>
</head>
<body>
    <section id="root">
        <header>
            <h1>记事本</h1>
            <input v-model="inputValue" @keyup.enter="add" autofocus="autofocus" autocomplete="off" placeholder="请输入任务">
        </header>

        <section class="main">
            <ul>
                <li v-for="(item,index) in list">
                    <div>
                        <label>{{index}}-{{item}} </label>
                        <button @click="remove(index)">删除</button>
                    </div>
                </li>
            </ul>
        </section>

        <footer>
            <strong v-if="list.length!=0">{{list.length}} itmes</strong>
            <button v-show="list.length!=0" @click="clear">清空</button>
        </footer>
    </section>
    <script>
        Vue.config.productionTip = false
        new Vue({
            el:'#root',
            data:{
                list:['aaa','bbb','cccc'],
                inputValue:'好好学习，天天向上'
            },
            methods: {
                add(){
                    this.list.push(this.inputValue)
                },
                remove(index){
                    this.list.splice(index,1)
                },
                clear(){
                    this.list = []
                }
            },
        })
    </script>
</body>
</html>